﻿using System;
using System.ComponentModel;
using System.Globalization;

namespace InputBoxes.Controls
{
    [ToolboxItem(true)]
    public class DateInputBox : OrderedValueTypeInputBoxBase<DateTime>
    {
        public DateInputBox()
        {
            _dateTimeStyles=DateTimeStyles.AssumeLocal;
        }

        private DateTimeStyles _dateTimeStyles;
        public DateTimeStyles DateTimeStyles
        {
            get { return _dateTimeStyles; }
            set
            {
                _dateTimeStyles = value;
                PerformValidate();
            }
        }

        protected override DateTime? Parse(string text)
        {
            DateTime value;
            return DateTime.TryParse(text, CultureInfo.CurrentUICulture, DateTimeStyles, out value) ? (DateTime?)value : null;
        }
    }
}